{$CLEO .cs}
{$USE CLEO+}
{$USE ini}

0000: NOP

script_name "WD Rifle"

// By ArtemQa146

if
    0AA2: 31@ = load_dynamic_library "CLEO+.cleo"
then
    if
        0AA4: 30@ = get_dynamic_library_procedure "GetCleoPlusVersion" library 31@
    then
        0AA7: call_function_return 30@ num_params 0 pop 0 29@
        if
            not 29@ >= 0x1020000
        then
            0AD1: show_formatted_text_highpriority "Cleo+ 1.2.0 (or higher) version is required, the Weapon Details mod is disabled" time 15000
            0AA3: free_dynamic_library 31@
            0A93: terminate_this_custom_script
        end
        0AA3: free_dynamic_library 31@
    end
else
    0AD1: show_formatted_text_highpriority "Cleo+ 1.2.0 (or higher) version is required, the Weapon Details mod is disabled" time 15000
    0AA3: free_dynamic_library 31@
    0A93: terminate_this_custom_script
end

if
    0E2D: is_game_first_start
then
    0F00: load_special_model_dff "Ak47\ak47_S" txd "Ak47\ak47" store_to 0@
    0AF1: write_int 0@ to_ini_file "cleo\LoadModels.ini" section "Models" key "ak47_S"
    0F00: load_special_model_dff "Ak47\ak47_R" txd "Ak47\ak47" store_to 0@
    0AF1: write_int 0@ to_ini_file "cleo\LoadModels.ini" section "Models" key "ak47_R"
    0F00: load_special_model_dff "Ak47\ak47_O" txd "Ak47\ak47" store_to 0@
    0AF1: write_int 0@ to_ini_file "cleo\LoadModels.ini" section "Models" key "ak47_O"
    0F00: load_special_model_dff "M4\M4_S" txd "M4\M4" store_to 0@
    0AF1: write_int 0@ to_ini_file "cleo\LoadModels.ini" section "Models" key "M4_S"
    0F00: load_special_model_dff "M4\M4_R" txd "M4\M4" store_to 0@
    0AF1: write_int 0@ to_ini_file "cleo\LoadModels.ini" section "Models" key "M4_R"
    0F00: load_special_model_dff "M4\M4_O" txd "M4\M4" store_to 0@
    0AF1: write_int 0@ to_ini_file "cleo\LoadModels.ini" section "Models" key "M4_O"
    0F00: load_special_model_dff "M4\M4_R2" txd "M4\M4" store_to 0@
    0AF1: write_int 0@ to_ini_file "cleo\LoadModels.ini" section "Models" key "M4_R2"
    0F00: load_special_model_dff "Mp5lng\Mp5lng_S" txd "Mp5lng\Mp5lng" store_to 0@
    0AF1: write_int 0@ to_ini_file "cleo\LoadModels.ini" section "Models" key "Mp5lng_S"
    0F00: load_special_model_dff "Mp5lng\Mp5lng_R" txd "Mp5lng\Mp5lng" store_to 0@
    0AF1: write_int 0@ to_ini_file "cleo\LoadModels.ini" section "Models" key "Mp5lng_R"
    0F00: load_special_model_dff "Mp5lng\Mp5lng_O" txd "Mp5lng\Mp5lng" store_to 0@
    0AF1: write_int 0@ to_ini_file "cleo\LoadModels.ini" section "Models" key "Mp5lng_O"
    0F00: load_special_model_dff "Mp5lng\Mp5lng_R2" txd "Mp5lng\Mp5lng" store_to 0@
    0AF1: write_int 0@ to_ini_file "cleo\LoadModels.ini" section "Models" key "Mp5lng_R2"
end

const
    Ak47_s = 31@
    Ak47_r = 30@
    Ak47_o = 29@
    Ak_Clip_Model = 28@
    AK_Clip_X = 27@
    AK_Clip_Y = 26@
    AK_Clip_Z = 25@
    M4_S = 24@
    M4_R = 23@
    M4_O = 22@
    M4_R2 = 21@
    M4_Clip_Model = 20@
    M4_Clip_X = 19@
    M4_Clip_Y = 18@
    M4_Clip_Z = 17@
    MP5_S = 16@
    MP5_R = 15@
    MP5_O = 14@
    MP5_R2 = 13@
    MP5_Clip_Model = 12@
    MP5_Clip_X = 11@
    MP5_Clip_Y = 10@
    MP5_Clip_Z = 9@
end

repeat
wait 0
until player.Defined(0)

0AF0: 0@ = read_int_from_ini_file "cleo\LoadModels.ini" section "Models" key "ak47_S"
0F02:  $PLAYER_ACTOR special_model 0@ bone 24 offset 0 0 0 rotation 0 0 0 scale Ak47_s // bone 34 left hand, 24 right hand, 9 had, 3 tors, 4 upper tors

0AF2: AK_Clip_X = get_float_from_ini_file "cleo\ak47.ini" section "settings" key "Clip X"
0AF2: AK_Clip_Y = get_float_from_ini_file "cleo\ak47.ini" section "settings" key "Clip Y"
0AF2: AK_Clip_Z = get_float_from_ini_file "cleo\ak47.ini" section "settings" key "Clip Z"
0AF0: Ak_Clip_Model = read_int_from_ini_file "cleo\LoadModels.ini" section "Models" key "ak47_R"
0F02:  $PLAYER_ACTOR special_model Ak_Clip_Model bone 24 offset AK_Clip_X AK_Clip_Y AK_Clip_Z rotation 0 0 0 scale Ak47_r // bone 34 left hand, 24 right hand, 9 had, 3 tors, 4 upper tors

0AF0: 0@ = read_int_from_ini_file "cleo\LoadModels.ini" section "Models" key "ak47_O"
0F02:  $PLAYER_ACTOR special_model 0@ bone 24 offset 0 0 0 rotation 0 0 0 scale Ak47_o // bone 34 left hand, 24 right hand, 9 had, 3 tors, 4 upper tors

0AF0: 0@ = read_int_from_ini_file "cleo\LoadModels.ini" section "Models" key "M4_S"
0F02:  $PLAYER_ACTOR special_model 0@ bone 24 offset 0 0 0 rotation 0 0 0 scale M4_S // bone 34 left hand, 24 right hand, 9 had, 3 tors, 4 upper tors

0AF2: M4_Clip_X = get_float_from_ini_file "cleo\m4.ini" section "settings" key "Clip X"
0AF2: M4_Clip_Y = get_float_from_ini_file "cleo\m4.ini" section "settings" key "Clip Y"
0AF2: M4_Clip_Z = get_float_from_ini_file "cleo\m4.ini" section "settings" key "Clip Z"
0AF0: M4_Clip_Model = read_int_from_ini_file "cleo\LoadModels.ini" section "Models" key "M4_R"
0F02:  $PLAYER_ACTOR special_model M4_Clip_Model bone 24 offset M4_Clip_X M4_Clip_Y M4_Clip_Z rotation 0 0 0 scale M4_R // bone 34 left hand, 24 right hand, 9 had, 3 tors, 4 upper tors

0AF0: 0@ = read_int_from_ini_file "cleo\LoadModels.ini" section "Models" key "M4_O"
0F02:  $PLAYER_ACTOR special_model 0@ bone 24 offset 0 0 0 rotation 0 0 0 scale M4_O // bone 34 left hand, 24 right hand, 9 had, 3 tors, 4 upper tors

0AF0: 0@ = read_int_from_ini_file "cleo\LoadModels.ini" section "Models" key "M4_R2"
0F02:  $PLAYER_ACTOR special_model 0@ bone 24 offset 0 0 0 rotation 0 0 0 scale M4_R2 // bone 34 left hand, 24 right hand, 9 had, 3 tors, 4 upper tors

0AF0: 0@ = read_int_from_ini_file "cleo\LoadModels.ini" section "Models" key "Mp5lng_S"
0F02:  $PLAYER_ACTOR special_model 0@ bone 24 offset 0 0 0 rotation 0 0 0 scale MP5_S // bone 34 left hand, 24 right hand, 9 had, 3 tors, 4 upper tors

0AF2: MP5_Clip_X = get_float_from_ini_file "cleo\Mp5lng.ini" section "settings" key "Clip X"
0AF2: MP5_Clip_Y = get_float_from_ini_file "cleo\Mp5lng.ini" section "settings" key "Clip Y"
0AF2: MP5_Clip_Z = get_float_from_ini_file "cleo\Mp5lng.ini" section "settings" key "Clip Z"
0AF0: MP5_Clip_Model = read_int_from_ini_file "cleo\LoadModels.ini" section "Models" key "Mp5lng_R"
0F02:  $PLAYER_ACTOR special_model MP5_Clip_Model bone 24 offset MP5_Clip_X MP5_Clip_Y MP5_Clip_Z rotation 0 0 0 scale MP5_R // bone 34 left hand, 24 right hand, 9 had, 3 tors, 4 upper tors

0AF0: 0@ = read_int_from_ini_file "cleo\LoadModels.ini" section "Models" key "Mp5lng_O"
0F02:  $PLAYER_ACTOR special_model 0@ bone 24 offset 0 0 0 rotation 0 0 0 scale MP5_O // bone 34 left hand, 24 right hand, 9 had, 3 tors, 4 upper tors

0AF0: 0@ = read_int_from_ini_file "cleo\LoadModels.ini" section "Models" key "Mp5lng_R2"
0F02:  $PLAYER_ACTOR special_model 0@ bone 24 offset 0 0 0 rotation 0 0 0 scale MP5_R2 // bone 34 left hand, 24 right hand, 9 had, 3 tors, 4 upper tors

0E31: set_render_object_visible Ak47_S 0
0E31: set_render_object_visible Ak47_R 0
0E31: set_render_object_visible Ak47_O 0

0E31: set_render_object_visible M4_S 0
0E31: set_render_object_visible M4_R 0
0E31: set_render_object_visible M4_O 0
0E31: set_render_object_visible M4_R2 0

0E31: set_render_object_visible MP5_S 0
0E31: set_render_object_visible MP5_R 0
0E31: set_render_object_visible MP5_O 0
0E31: set_render_object_visible MP5_R2 0


while true
wait 0
    if
        player.Defined(0)
    then
        if
            actor.Driving($PLAYER_ACTOR)
        then
            continue
        end

        0AAA: 1@ = get_script_struct_named 'Ak47'
        if and
            02D8:   actor $PLAYER_ACTOR current_weapon == 30
            1@ == 0
        then
            0A92: stream_custom_script "Ak47.qa" Ak47_s Ak47_r Ak47_o AK_Clip_Model AK_Clip_X AK_Clip_Y AK_Clip_Z
            timera = 0
            repeat
            wait 0
            if timera > 500
            then break
            end
            0AAA: 1@ = get_script_struct_named 'Ak47'
            until 1@ > 0
            continue
        end
        
        0AAA: 1@ = get_script_struct_named 'M4'
        if and
            02D8:   actor $PLAYER_ACTOR current_weapon == 31
            1@ == 0
        then
            0A92: stream_custom_script "M4.qa" M4_S M4_R M4_O M4_Clip_Model M4_Clip_X M4_Clip_Y M4_Clip_Z M4_R2
            timera = 0
            repeat
            wait 0
            if timera > 500
            then break
            end
            0AAA: 1@ = get_script_struct_named 'M4'
            until 1@ > 0
            continue
        end
        
        0AAA: 1@ = get_script_struct_named 'Mp5'
        if and
            02D8:   actor $PLAYER_ACTOR current_weapon == 29
            1@ == 0
        then
            0A92: stream_custom_script "Mp5lng.qa" MP5_S MP5_R MP5_O MP5_Clip_Model MP5_Clip_X MP5_Clip_Y MP5_Clip_Z MP5_R2
            timera = 0
            repeat
            wait 0
            if timera > 500
            then break
            end
            0AAA: 1@ = get_script_struct_named 'Mp5'
            until 1@ > 0
            continue
        end

    end
end